﻿using IntelligentAgriculture.Contracts.Dto.Input.ManageInput;
using IntelligentAgriculture.Contracts.Dto.Output.ManageOutput;
using IntelligentAgriculture.Contracts.Interface.ColumnManagements;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.WebAPI.Application.Command.ColumnManageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;

using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using IntelligentAgriculture.Contracts.Dto.Output.ColumnManagementOutput;
using IntelligentAgriculture.Contracts.Dto.Input.ColumnManagemeninput;
using IntelligentAgriculture.Contracts.Dto.Output.PageOutput;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.ColumnManageCommandHandler;

namespace IntelligentAgriculture.WebAPI.Controllers.ColumnManagecontroller
{
    /// <summary>
    /// 栏位管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ColumnManagesController : ControllerBase
    {
        private readonly IColumnManageService _icolumnManageService;
        private readonly TokenService _tokenService;
        private readonly IMediator _mediator;

        
        public ColumnManagesController(IColumnManageService icolumnManageService, TokenService tokenService, IMediator mediator)
        {
            _icolumnManageService = icolumnManageService;
            _tokenService = tokenService;
            _mediator = mediator;
        }



        /// <summary>
        /// 栏位添加功能
        /// </summary>
        /// <param name="coomand">添加实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Results<int>> AddManager(ColumnManageAddCommand coomand)
        {
            try
            {
                return await _mediator.Send(coomand);

            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 显示，分页，查询功能
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PagesOutput<ColumnShowOutput>>> GetShow(ColumnShowinput? input)
        {
            try
            {
                var list = new ColumnManageShowCommand(input);
                return await _mediator.Send(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 根据栋舍获取栏位
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<IQueryable<Columnmanagement>>> GetColumn(int ridgepoleId)
        {
			try
			{
                var command=new GetColumnManagementCommand(ridgepoleId);
				return await _mediator.Send(command);
			}
			catch (Exception)
			{

				throw;
			}
		}

	}
}
